<?php

require_once './aip-php-sdk/AipOcr.php';
require_once './common.php';

// 你的 APPID AK SK
const APP_ID = '18847651';
const API_KEY = 'ztmeDRa9acVYdjQImFHsklHd';
const SECRET_KEY = 'r8hOSdieu0hCc5nB0fSpv0Z2vraifOX7';

$client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

must_post_request();

handle_formUrlencoded('image', function ($data) {
    $option = array();
    $options["language_type"] = "CHN_ENG";
    $options["detect_direction"] = "true";
    $options["detect_language"] = "true";
    $options["probability"] = "true";
    global $client;
    $ret = $client->basicGeneral($data, $option);
    echo $ret;
});

handle_formdata_file('image', function ($data) {
    $option = array();
    $options["language_type"] = "CHN_ENG";
    $options["detect_direction"] = "true";
    $options["detect_language"] = "true";
    $options["probability"] = "true";
    global $client;
    $ret = $client->basicGeneral($data, $option);
    // var_dump($ret);
    echo json_encode($ret, JSON_UNESCAPED_UNICODE);
});
